<template>
  <div class="">
    <div class="">
      <SearchComp :searchForm="searchForm" :searchData="queryString" :searchAction="searchAction"></SearchComp>
    </div>
    <div class="m-t">
      <div class="btnStyle flex-a-c  ">
        <el-button type="primary" size="small">批量发布</el-button>
        <el-button type="danger" size="small" @click="dels">批量撤销</el-button>
      </div>
      <TableCompEle class="m-t" ref="multipleTable" height="50vh" :tableData="tableData" :tableConfig="tableConfig" :tableAction="tableAction"
        :isSelect="true" :isIndex="true" :isShowPage="true" :queryParams="queryParams" @getPagination="getList"
        @handleSelectionChange="handleSelectionChange"></TableCompEle>
    </div>
    <Add ref="addRef" @close="getList" />
  </div>
</template>

<script>
import {
  // getArticleList,
  batchDelete,
  downloadTemplate,
  importRegulations
} from '@/api/publishManage'
import Add from './common/add.vue'
export default {
  components: { Add },
  data() {
    return {
      flag: 1,
      multipleSelection: [],
      queryParams: {
        total: 0,
        currentPage: 1,
        pageSize: 10
      },
      tableData: [],
      tableConfig: [
        {
          prop: 'title',
          label: '标题'
        },
        {
          prop: 'source',
          label: '来源'
        },
        {
          prop: 'modifyBy',
          label: '发布时间'
        }
      ],
      tableAction: {
        align: () => 'center',
        width: () => String(300),
        operations: [
          {
            label: '查看',
            isLink: true,
            type: 'primary',
            method: row => {
              this.$refs.addRef.show({
                title: '查看政策法规',
                isLook: true,
                flag: this.flag,
                data: row
              })
            }
          },
          {
            label: '发布',
            isLink: true,
            type: 'primary',
            method: row => {
              this.$refs.addRef.show({
                title: '修改政策法规',
                isLook: false,
                flag: this.flag,
                data: row
              })
            }
          },
          {
            label: '撤销发布',
            isLink: true,
            type: 'danger',
            method: row => {
              this.deleteFun([row.articleId])
            }
          },
          {
            label: '置顶',
            isLink: true,
            type: 'primary',
            method: row => {
              this.$refs.addRef.show({
                title: '修改政策法规',
                isLook: false,
                flag: this.flag,
                data: row
              })
            }
          },
          {
            label: '撤销置顶',
            isLink: true,
            type: 'danger',
            method: row => {
              this.deleteFun([row.articleId])
            }
          }
        ]
      },
      queryString: {
        title: '',
        source: ''
      },
      searchForm: {
        changeMethod: () => {
          this.queryParams.currentPage = 1
          this.getList()
        },
        formData: [
          {
            type: 'Input',
            label: '标题',
            prop: 'title',
            clearable: true,
            icon: 'el-icon-search',
            placeholder: '请输入标题'
          },
          {
            type: 'Input',
            label: '来源',
            prop: 'source',
            clearable: true,
            icon: 'el-icon-search',
            placeholder: '请输入来源'
          }
        ]
      },
      searchAction: [
        {
          label: '查询',
          type: 'primary',
          handle: () => {
            this.queryParams.currentPage = 1
            this.$refs.multipleTable.clearSelection()
            this.getList()
          }
        },
        {
          label: '重置',
          type: 'primary',
          plain: true,
          handle: () => {
            this.queryString = {
              title: '',
              source: ''
            }
            this.queryParams.currentPage = 1
            this.getList()
          }
        }
      ]
    }
  },
  created() {
    this.getList()
  },
  mounted() { },
  methods: {
    add() {
      this.$refs.addRef.show({
        title: '新增通知信息',
        isLook: false,
        flag: this.flag
      })
    },
    download() {
      downloadTemplate()
    },
    dels() {
      if (this.multipleSelection.length == 0) {
        this.$message({
          type: 'warning',
          message: '请选择要删除的数据'
        })
        return
      }
      const ids = []
      this.multipleSelection.forEach(items => {
        ids.push(items.articleId)
      })
      this.deleteFun(ids)
    },
    getList() {
      let res = {
        code: 200,
        message: '操作成功',
        data: {
          pageSize: 10,
          totalPage: 1,
          total: 8,
          list: [
            {
              articleId: 145,
              title: '关于开展2024年第一批首都科技创新券领取工作的通知',
              source: '北京市科学技术委员会、中关村科技园区管理委员会',
              content:
                '为贯彻落实《中华人民共和国国民经济和社会发展第十四个五年规划和2035年远景目标纲要》和《中共中央 国务院关于构建更加完善的要素市场化配置体制机制的意见》，建设高标准技术要素市场，科技部编制了《“十四五”技术要素市场专项规划》。现印发给你们，请结合实际情况认真贯彻实施。',
              state: '已发布',
              fileId: 886,
              deleteFlag: 'n',
              createTime: [2023, 6, 13, 15, 18, 27],
              createBy: '106',
              modifyTime: [2023, 6, 13, 15, 18, 27],
              modifyBy: '2023-03-12',
              version: 'V0.1',
              flag: 1,
              publishTime: '2023-06-13 15:18:31',
              commentCount: 1
            },
            {
              articleId: 144,
              title: '关于公示2023年首都科技条件平台开放单位名单的通知',
              source: '北京市科学技术委员会、中关村科技园区管理委员会网站',
              content:
                '现将《关于加强高水平科技成果转移转化人才队伍建设的若干措施》印发给你们，请结合实际认真贯彻落实。',
              state: '已发布',
              fileId: 885,
              deleteFlag: 'n',
              createTime: [2023, 6, 13, 15, 17, 12],
              createBy: '106',
              modifyTime: [2023, 6, 13, 15, 17, 28],
              modifyBy: '2023-03-12',
              version: 'V1,0',
              flag: 1,
              publishTime: '2023-06-13 15:17:17',
              commentCount: 0
            },
            {
              articleId: 143,
              title: '关于公示2023年首都科技条件平台开放单位名单的通知',
              source: '北京市科学技术委员会、中关村科技园区管理委员会网站',
              content:
                '为贯彻落实党中央、国务院关于加强数字政府建设的决策部署，持续提高专利审查服务信息化和便利化水平，国家知识产权局自2023年2月7日（含当日）起，全面推行专利证书电子化。当事人以电子形式申请并获得专利授权的，通过专利业务办理系统下载电子专利证书；以纸质形式申请并获得专利授权的，按照《领取电子专利证书通知书》中告知的方式下载电子专利证书。',
              state: '已发布',
              fileId: 884,
              deleteFlag: 'n',
              createTime: [2023, 6, 13, 15, 15, 9],
              createBy: '106',
              modifyTime: [2023, 6, 13, 15, 15, 9],
              modifyBy: '2023-03-12',
              version: 'V1.0',
              flag: 1,
              publishTime: '2023-06-13 15:15:21',
              commentCount: 0
            },
            {
              articleId: 142,
              title: '关于征集中关村论坛2024年系列活动的通知',
              source: '北京市科委、中关村管委会网站',
              content:
                '各省、自治区、直辖市和新疆生产建设兵团知识产权局，四川省知识产权服务促进中心，各地方有关中心：\n\n为贯彻落实中共中央、国务院印发的《知识产权强国建设纲要（2021—2035年）》和国务院印发的《“十四五”国家知识产权保护和运用规划》，加强知识产权维权援助工作指导，完善工作流程，强化规范化管理，经广泛征求地方意见，制定形成《知识产权维权援助工作指引》，现印发给你们，请在工作中结合实际参照推行，进一步',
              state: '已发布',
              fileId: 883,
              deleteFlag: 'n',
              createTime: [2023, 6, 13, 15, 12, 3],
              createBy: '106',
              modifyTime: [2023, 6, 13, 15, 13, 57],
              modifyBy: '2023-03-12',
              version: '1.0',
              flag: 1,
              publishTime: '2023-06-13 15:12:21',
              commentCount: 0
            },
            {
              articleId: 130,
              title: '关于征集测试检验服务平台项目的通知',
              source: '北京市海淀区人民政府网站',
              content: '要严格遵守单位制定的管理制度。',
              state: '已发布',
              fileId: 825,
              deleteFlag: 'n',
              createTime: [2023, 6, 1, 9, 51, 19],
              createBy: '1261',
              modifyTime: [2023, 6, 1, 9, 51, 19],
              modifyBy: '2023-03-12',
              version: 'V1.0',
              flag: 1,
              publishTime: '2023-06-01 09:54:33',
              commentCount: 0
            },
            {
              articleId: 129,
              title: '关于征集智能检测装备创新产品的函',
              source: '工业和信息化部网站',
              content:
                '所有的经费收入支出必须符合单位规定的审批标准方可审批通过。',
              state: '已发布',
              fileId: 824,
              deleteFlag: 'n',
              createTime: [2023, 6, 1, 9, 50, 15],
              createBy: '1261',
              modifyTime: [2023, 6, 1, 9, 50, 15],
              modifyBy: '2023-03-12',
              version: 'V1.0',
              flag: 1,
              publishTime: '2023-06-01 09:54:34',
              commentCount: 0
            },
            {
              articleId: 128,
              title: '关于开展2023年第一批首都科技创新券领取工作的通知',
              source: '北京市科学技术委员会、中关村科技园区管理委员会',
              content: '按照单位规定的方案进行实施运行',
              state: '已发布',
              fileId: 823,
              deleteFlag: 'n',
              createTime: [2023, 6, 1, 9, 48, 35],
              createBy: '1261',
              modifyTime: [2023, 6, 1, 9, 48, 35],
              modifyBy: '2023-03-12',
              version: 'V0.8',
              flag: 1,
              publishTime: '2023-06-01 09:54:37',
              commentCount: 0
            },
            {
              articleId: 127,
              title:
                '关于发布京津冀科技创新券服务提供机构（开放实验室）目录（2023）的通知',
              source: '北京市科学技术委员会、中关村科技园区管理委员会',
              content: '必须符合本单位规定的审核标准方可审核通过',
              state: '已发布',
              fileId: 822,
              deleteFlag: 'n',
              createTime: [2023, 6, 1, 9, 47, 47],
              createBy: '1261',
              modifyTime: [2023, 6, 1, 9, 47, 47],
              modifyBy: '2023-03-12',
              version: 'V1.0',
              flag: 1,
              publishTime: '2023-06-01 09:54:39',
              commentCount: 0
            }
          ],
          page: 1
        }
      }
      // getArticleList(
      //   Object.assign(
      //     {
      //       currentPage: this.queryParams.currentPage,
      //       pageSize: this.queryParams.pageSize
      //     },
      //     this.queryString,
      //     { flag: this.flag }
      //   )
      // ).then(res => {
      this.queryParams.total = res?.data?.total ?? 0
      this.tableData = res?.data?.list ?? []
      // })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    deleteFun(ids) {
      this.$confirm(`确定要删除吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          batchDelete({
            ids: ids
          }).then(() => {
            this.$refs.multipleTable.clearSelection()
            this.getList()
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    // xls
    handleChangeXls(file) {
      const _file = file?.raw ?? file
      const formData = new FormData()
      formData.append('file', _file)
      formData.append('pathType', file.name.split('.').pop())
      importRegulations(formData).then(() => {
        this.getList()
      })
    },
    // 多次上传覆盖
    handleExceedXls(file) {
      this.$refs.uploadRefXls.clearFiles()
      this.handleChangeXls(file[0])
    }
  }
}
</script>

<style lang="less" scoped>
  .upload-demo {
    padding: 0 10px;
  }
</style>